package com.lagou.client;

import com.lagou.server.Exam;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.util.ArrayList;

//管理员系统->考题管理模块桌面显示
public class ExamView {
    private ClientInitClose cic;
    public ExamView(ClientInitClose cic) {
        this.cic = cic;
    }
    public void examShow() throws IOException, ClassNotFoundException {





    boolean flag = true;

    while(flag)

    {
        System.out.println("  \n\n\t\t   考题管理模块");
        System.out.println("-------------------------------------------");
        System.out.print("   [1] 增加考题");
        System.out.println("     [2] 修改考题");
        System.out.print("   [3] 删除考题");
        System.out.println("     [4] 查询考题");
        System.out.print("   [5] 导入考题");
        System.out.println("     [6] 返回上一菜单");
        System.out.println("-------------------------------------------");


        int choose = ClientScanner.getScanner().nextInt();
        switch (choose) {
            case 1:

                cic.getOos().writeObject("add");
                System.out.println("请输入增加的题目");
                //int number1=ClientScanner.getScanner().nextInt();
                String sub1 = ClientScanner.getScanner().next();
                Exam exa1 = new Exam(sub1);
                System.out.println("选项A：");
                String a = ClientScanner.getScanner().next();
                exa1.setChooseA(a);
                System.out.println("选项B：");
                String b = ClientScanner.getScanner().next();
                exa1.setChooseB(b);
                System.out.println("选项C：");
                String c = ClientScanner.getScanner().next();
                exa1.setChooseC(c);
                System.out.println("答案：");
                String answer = ClientScanner.getScanner().next();
                exa1.setAnswer(answer);
                cic.getOos().writeObject(exa1);
                break;
            case 2:
                cic.getOos().writeObject("change");
                ArrayList<Exam> remarry = (ArrayList<Exam>) cic.getOis().readObject();
                for (Exam e : remarry) {
                    System.out.println(e);
                }
                System.out.println("请输入修改的题号及修改后的题目");
                int number2 = ClientScanner.getScanner().nextInt();
                String sub2 = ClientScanner.getScanner().next();
                Exam exa2 = new Exam(number2, sub2);
                System.out.println("选项A：");
                String a1 = ClientScanner.getScanner().next();
                exa2.setChooseA(a1);
                System.out.println("选项B：");
                String b1 = ClientScanner.getScanner().next();
                exa2.setChooseB(b1);
                System.out.println("选项C：");
                String c1 = ClientScanner.getScanner().next();
                exa2.setChooseC(c1);
                System.out.println("答案：");
                String answer1 = ClientScanner.getScanner().next();
                exa2.setAnswer(answer1);
                cic.getOos().writeObject(exa2);
                break;
            case 3:
                cic.getOos().writeObject("cut");
                ArrayList<Exam> array1 = (ArrayList<Exam>) cic.getOis().readObject();
                //System.out.println("收到的题库"+array1);
                for (Exam e : array1) {
                    System.out.println(e);
                }
                System.out.println("请输入删除的题号");
                int number3 = ClientScanner.getScanner().nextInt();
                cic.getOos().writeObject(number3);
                break;
            case 4:
                cic.getOos().writeObject("search");
                System.out.println("请输入查找题目的关键字");
                String name3 = ClientScanner.getScanner().next();
                cic.getOos().writeObject(name3);
                Exam exa = (Exam) cic.getOis().readObject();
                System.out.println(exa);
                break;
            case 5:
                cic.getOos().writeObject("examImport");
                ObjectInputStream exois = null;
                exois = new ObjectInputStream(new FileInputStream("G:\\学生在线系统\\考题1.txt"));   //文件里是考题对象信息 ，一个列表
                if (exois != null) {
                    ArrayList<Exam> exlist = (ArrayList<Exam>) exois.readObject();
                    cic.getOos().writeObject(exlist);
                    System.out.println("导入题库!");
                }
                break;
            case 6:
                cic.getOos().writeObject("exit");
                flag = false;
                break;
        }
    }
    }
}
